/*
 * Copyright 2020-2030 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

package com.gitee.minimalismstyle.fresh.flowable.api.feign

import org.springframework.web.bind.annotation.*
import com.gitee.minimalismstyle.fresh.common.core.domain.R
import com.gitee.minimalismstyle.fresh.flowable.api.annotation.FlowableClient
import com.gitee.minimalismstyle.fresh.flowable.api.config.FlowableFeignConfig
import com.gitee.minimalismstyle.fresh.flowable.api.feign.model.*

/**
 * History
 * @author maoxiaodong
 */
@FlowableClient(configuration = [FlowableFeignConfig::class])
interface HistoryApi {


    /**
     * List historic activity instances
     */
    @GetMapping("/history/historic-activity-instances")
    fun listHistoricActivityInstances(
        @RequestParam(name = "activityId", required = false) activityId: String?,
        @RequestParam(name = "activityInstanceId", required = false) activityInstanceId: String?,
        @RequestParam(name = "activityName", required = false) activityName: String?,
        @RequestParam(name = "activityType", required = false) activityType: String?,
        @RequestParam(name = "executionId", required = false) executionId: String?,
        @RequestParam(name = "finished", required = false) finished: Boolean?,
        @RequestParam(name = "taskAssignee", required = false) taskAssignee: String?,
        @RequestParam(name = "processInstanceId", required = false) processInstanceId: String?,
        @RequestParam(name = "processDefinitionId", required = false) processDefinitionId: String?,
        @RequestParam(name = "tenantId", required = false) tenantId: String?,
        @RequestParam(name = "tenantIdLike", required = false) tenantIdLike: String?,
        @RequestParam(name = "withoutTenantId", required = false) withoutTenantId: Boolean?
    ): R<DataResponse<HistoricActivityInstanceResponse>>

    /**
     * Get historic detail
     */
    @GetMapping("/history/historic-detail")
    fun listHistoricDetails(
        @RequestParam(name = "id", required = false) id: String?,
        @RequestParam(name = "processInstanceId", required = false) processInstanceId: String?,
        @RequestParam(name = "executionId", required = false) executionId: String?,
        @RequestParam(name = "activityInstanceId", required = false) activityInstanceId: String?,
        @RequestParam(name = "taskId", required = false) taskId: String?,
        @RequestParam(name = "selectOnlyFormProperties", required = false) selectOnlyFormProperties: Boolean?,
        @RequestParam(name = "selectOnlyVariableUpdates", required = false) selectOnlyVariableUpdates: Boolean?
    ): R<DataResponse<HistoricDetailResponse>>

    /**
     * The response body contains the binary value of the variable. When the variable is of type binary, the content-type of the response is set to application/octet-stream, regardless of the content of the variable or the request accept-type header. In case of serializable, application/x-java-serialized-object is used as content-type.
     */
    @GetMapping("/history/historic-detail/{detailId}/data")
    fun getHistoricDetailVariableData(
        @PathVariable("detailId") detailId: String
    ): R<Any>

    /**
     * The response body contains the binary value of the variable. When the variable is of type binary, the content-type of the response is set to application/octet-stream, regardless of the content of the variable or the request accept-type header. In case of serializable, application/x-java-serialized-object is used as content-type.
     */
    @GetMapping("/history/historic-task-instances/{taskId}/variables/{variableName}/data")
    fun getHistoricTaskInstanceVariableData(
        @PathVariable("taskId") taskId: String,
        @PathVariable("variableName") variableName: String,
        @RequestParam(name = "scope", required = false) scope: String?
    ): R<Any>

    /**
     * List of historic variable instances
     */
    @GetMapping("/history/historic-variable-instances")
    fun listHistoricVariableInstances(
        @RequestParam(name = "processInstanceId", required = false) processInstanceId: String?,
        @RequestParam(name = "taskId", required = false) taskId: String?,
        @RequestParam(name = "excludeTaskVariables", required = false) excludeTaskVariables: Boolean?,
        @RequestParam(name = "variableName", required = false) variableName: String?,
        @RequestParam(name = "variableNameLike", required = false) variableNameLike: String?
    ): R<DataResponse<HistoricVariableInstanceResponse>>

    /**
     * The response body contains the binary value of the variable. When the variable is of type binary, the content-type of the response is set to application/octet-stream, regardless of the content of the variable or the request accept-type header. In case of serializable, application/x-java-serialized-object is used as content-type.
     */
    @GetMapping("/history/historic-variable-instances/{varInstanceId}/data")
    fun getHistoricInstanceVariableData(
        @PathVariable("varInstanceId") varInstanceId: String
    ): R<Any>

    /**
     * All supported JSON parameter fields allowed are exactly the same as the parameters found for getting a collection of historic task instances, but passed in as JSON-body arguments rather than URL-parameters to allow for more advanced querying and preventing errors with request-uri’s that are too long.
     */
    @PostMapping("/query/historic-activity-instances")
    fun queryActivityInstances(
        @RequestBody(required = false) body: HistoricActivityInstanceQueryRequest?
    ): R<DataResponse<HistoricActivityInstanceResponse>>

    /**
     * All supported JSON parameter fields allowed are exactly the same as the parameters found for getting a collection of historic process instances, but passed in as JSON-body arguments rather than URL-parameters to allow for more advanced querying and preventing errors with request-uri’s that are too long.
     */
    @PostMapping("/query/historic-detail")
    fun queryHistoricDetail(
        @RequestBody(required = false) body: HistoricDetailQueryRequest?
    ): R<DataResponse<HistoricDetailResponse>>

    /**
     * All supported JSON parameter fields allowed are exactly the same as the parameters found for getting a collection of historic process instances, but passed in as JSON-body arguments rather than URL-parameters to allow for more advanced querying and preventing errors with request-uri’s that are too long. On top of that, the query allows for filtering based on process variables. The variables property is a JSON-array containing objects with the format as described here.
     */
    @PostMapping("/query/historic-variable-instances")
    fun queryVariableInstances(
        @RequestBody(required = false) body: HistoricVariableInstanceQueryRequest?
    ): R<DataResponse<HistoricVariableInstanceResponse>>
}